package com.dubbo.regulate.service;
import java.util.Date;

import com.alibaba.dubbo.config.annotation.Service;

import com.dubbo.common.dtos.AppHttpCodeEnum;

import com.dubbo.common.dtos.PageResponseResult;
import com.dubbo.common.dtos.ResponseResult;
import com.dubbo.common.exception.LeadNewsException;
import com.dubbo.model.balance.dtos.PageRequestDto;
import com.dubbo.model.regulate.dtos.RegProductDto;
import com.dubbo.model.regulate.pojos.RegProduct;
import com.dubbo.regulate.CatalogService;
import com.dubbo.regulate.mapper.CatalogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Service
@Component
public class CarCatalogService implements CatalogService {

    @Autowired
    private CatalogMapper catalogMapper;

    //服务目录分页查询
    @Override
    public ResponseResult<List<RegProduct>> ParentsCatalogList(PageRequestDto dto) {
        //设置页码大小
        dto.checkParam();
        Integer page = dto.getPage();
        dto.setPage((page - 1) * dto.getSize());

        Integer count = catalogMapper.count();//查询总条数
        List<RegProduct> productList = catalogMapper.parentsCatalogList(dto);

        PageResponseResult pageResponseResult = new PageResponseResult(page, dto.getSize(), count);
        pageResponseResult.setData(productList);

        return pageResponseResult;
    }

    /*
    上下架
    * */
    @Override
    public ResponseResult SoldOutUp(RegProductDto dto) {
        //参数校验
        if (dto.getId() == null || dto.getPState() == null){
           throw new LeadNewsException(AppHttpCodeEnum.PARAM_INVALID);
        }
         catalogMapper.SoldOut(dto);
        return null;
    }


}
